import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from common.Utils import pilotDriver
class Register:
    url=""
    driver=""
    def __init__(self):
        self.url="https://www.codepilot.fun/user/register"
        self.driver=pilotDriver.driver
        self.driver.get(self.url)
    def registerone(self):
        self.driver.find_element(By.CSS_SELECTOR,"#userRegisterPage > div > div.ant-pro-form-login-main.css-ccdg5a > form > button > span").click()
        try:
            self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-top.css-ccdg5a.css-ccdg5a > div.ant-pro-form-login-header.css-ccdg5a > span.ant-pro-form-login-title.css-ccdg5a")
        except:
            print("什么都不填,无法注册")
    def registertwo(self):
        self.driver.find_element(By.CSS_SELECTOR,"#userPassword").send_keys("zma123456")
        self.driver.find_element(By.CSS_SELECTOR,"#checkPassword").send_keys("zma123456")
        self.driver.find_element(By.CSS_SELECTOR,"#userRegisterPage > div > div.ant-pro-form-login-main.css-ccdg5a > form > button > span").click()
        try:
            self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-top.css-ccdg5a.css-ccdg5a > div.ant-pro-form-login-header.css-ccdg5a > span.ant-pro-form-login-title.css-ccdg5a")
        except:
            print("只填密码,无法注册")
    def registerthree(self):
        self.driver.find_element(By.CSS_SELECTOR,"#userAccount").send_keys("gf123")
        self.driver.find_element(By.CSS_SELECTOR,"#userRegisterPage > div > div.ant-pro-form-login-main.css-ccdg5a > form > button > span").click()
        try:
            self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-top.css-ccdg5a.css-ccdg5a > div.ant-pro-form-login-header.css-ccdg5a > span.ant-pro-form-login-title.css-ccdg5a")
        except:
            print("只填账号,无法注册")
    def registerfour(self):
        self.driver.find_element(By.CSS_SELECTOR,"#userAccount").send_keys("gf123")
        self.driver.find_element(By.CSS_SELECTOR, "#userPassword").send_keys("zma123456")
        self.driver.find_element(By.CSS_SELECTOR, "#checkPassword").send_keys("gf123456")
        try:
            self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-top.css-ccdg5a.css-ccdg5a > div.ant-pro-form-login-header.css-ccdg5a > span.ant-pro-form-login-title.css-ccdg5a")
        except:
            print("密码和确认密码不同,无法注册")

    def registerfive(self):
        #判断账户和密码长度过短或长是否可以注册
        ##1.首先判断账户
        # result = ""
        # list1=[]
        # for i in range(1,10):
        #     #1 12 123 1234 12345
        #     result+=str(i)
        #
        #     list1.append(result)
        #     print(list1)
        #     #print(int(result))
        # for cur in list1:
        #     print(cur)
        #     self.driver.find_element(By.CSS_SELECTOR, "#userAccount").send_keys(cur)
        #     self.driver.find_element(By.CSS_SELECTOR, "#userPassword").send_keys("zma123456")
        #     self.driver.find_element(By.CSS_SELECTOR, "#checkPassword").send_keys("zma123456")
        #     self.driver.find_element(By.CSS_SELECTOR,"#userRegisterPage > div > div.ant-pro-form-login-main.css-ccdg5a > form > button > span").click()
        #     self.driver.refresh()
        #     time.sleep(5)
        #     try:
        #         text=self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-top.css-ccdg5a.css-ccdg5a > div.ant-pro-form-login-header.css-ccdg5a > span.ant-pro-form-login-title.css-ccdg5a").text
        #         print(text)
        #         print("注册成功")
        #         print(list1.index(cur))
        #         time.sleep(2)
                #登陆管理员，删除注册信息。避免多次测试重复账户造成注册失败
                self.driver.get("https://www.codepilot.fun/user/login")
                self.driver.maximize_window()
                self.driver.find_element(By.CSS_SELECTOR, "#userAccount").send_keys("monai")
                self.driver.find_element(By.CSS_SELECTOR, "#userPassword").send_keys("12345678")

                self.driver.find_element(By.CSS_SELECTOR,"#userLoginPage > div > div.ant-pro-form-login-main.css-ccdg5a > form > button > span").click()

                time.sleep(2)

                self.driver.get("https://www.codepilot.fun/admin/user")
                for j in range(1,100):
                    ret=self.driver.find_elements(By.CSS_SELECTOR,"#basicLayout > div > div.ant-layout.css-ccdg5a > div > main > div > div.ant-pro-grid-content.css-ccdg5a > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper.css-ccdg5a > div > div > div > div > div > table > tbody > tr:nth-child(i)")
                for i in ret:
                    print(i.text)
            # except:
            #     print("注册失败")
            #     self.driver.find_element(By.CSS_SELECTOR, "#userAccount").clear()
            #     self.driver.find_element(By.CSS_SELECTOR, "#userPassword").clear()
            #     self.driver.find_element(By.CSS_SELECTOR, "#checkPassword").clear()



register=Register()
#register.registerone()
# register.registertwo()
# register.registerthree()
# register.registerfour()
register.registerfive()



